<?php
/**
* Form Elements
*
* Standard Elements for the Form are defined
*
* <code>
*  $form = new Form_Form_Elements();
*  $form->firstname());
*  $form->phone());
*  $form->email(true));
*  $form->message());
*  $form->send()
* </code>
*
* @author Mario Schillermann <info@rockit-flash.com>
* @encoding UTF-8 äöüßÖÄÜ
* @copyright © 2011 Mario Schillermann (info@rockit-flash.com)
* @license GNU GPL v2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
* @package Form_Form
* @subpackage Form_Form_Elements
* @phpVersion >=5
* @todo
*/

class Admin_Form_Elements extends Zend_Form
{
    protected $_language = array();

    function init() {
        $this->_language = array(
            'stringLengthTooShort' => 'Custom: Too Short - Must contain at least %min% characters',
            'stringLengthTooLong' =>  'Custom: Too Long - Must not contain more than %max% characters'
        );
    }

    protected function _validateNotEmpty($required, $label)
    {
        if($required === true)
            return array(
                'validator' => 'NotEmpty',
                'breakChainOnFailure' => true,
                'options' => array(
                    'messages' => array(
                        'isEmpty' => 'Das Feld "' . $label . '" darf nicht leer sein!'
                    )
                )
            );
    }
    /**
     * Form Element Firstname
     *
     * @param boolean $required
     * @param string  $label
     *
     * @return Zend_Form_Element_Text
     */
    public function firstname($required = false, $label = 'Vorname')
    {
        $this->addElement(new Zend_Form_Element_Text(
            'firstname',
            array(
                'label' => $label,
                'validators' => array(
                    //$this->_validateNotEmpty($required, $label),
                    array(
                        'validator'   => 'Regex',
                        'breakChainOnFailure' => true,
                        'options'     => array(
                            'pattern' =>
                                '/^[a-zA-ZŠšŽžŸÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØ' .
                                'ÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüý' .
                                'þÿñçĝğĞĜ\- ]{2,50}$/',
                            'messages' => array(
                                Zend_Validate_Regex::NOT_MATCH =>
                                    'Bitte geben Sie einen gültigen' .
                                    'Vornamen ein.'
                            )
                        )
                    )
                )
            )
        ));
    }
    /**
     * Form Element Firstname
     *
     * @param boolean $required
     * @param string  $label
     *
     * @return Zend_Form_Element_Text
     */
    public function lastname($required = false, $label = 'Nachname')
    {
        $this->addElement(new Zend_Form_Element_Text(
            'nachname',
            array(
                'label' => $label,
                'validators' => array(
                    //$this->_validateNotEmpty($required, $label),
                    array(
                        'validator'   => 'Regex',
                        'breakChainOnFailure' => true,
                        'options'     => array(
                            'pattern' =>
                                '/^[a-zA-ZŠšŽžŸÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØ' .
                                'ÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüý' .
                                'þÿñçĝğĞĜ\- ]{2,50}$/',
                            'messages' => array(
                                Zend_Validate_Regex::NOT_MATCH =>
                                    'Bitte geben Sie einen gültigen' .
                                    'Nachnamen ein.'
                            )
                        )
                    )
                )
            )
        ));
    }
        /**
     * Form Element Firstname
     *
     * @param boolean $required
     * @param string  $label
     *
     * @return Zend_Form_Element_Text
     */
    public function username($required = false, $label = 'Nachname')
    {
        $this->addElement(new Zend_Form_Element_Text(
            'nachname',
            array(
                'label' => $label,
                'validators' => array(
                    //$this->_validateNotEmpty($required, $label),
                    array(
                        'validator'   => 'Regex',
                        'breakChainOnFailure' => true,
                        'options'     => array(
                            'pattern' =>
                                '/^[a-zA-ZŠšŽžŸÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØ' .
                                'ÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüý' .
                                'þÿñçĝğĞĜ0-9\- ]{2,50}$/',
                            'messages' => array(
                                Zend_Validate_Regex::NOT_MATCH =>
                                    'EIngabe ist nicht gültig.'
                            )
                        )
                    )
                )
            )
        ));
    }
    /**
     * Form Element Firstname
     *
     * @param boolean $required
     * @param string  $label
     *
     * @return Zend_Form_Element_Textarea
     */
    public function password($required = false, $label = 'Passwort', $length = 50)
    {
        $this->addElement(new Zend_Form_Element_Text(
            'password',
            array(
                'label' => $label,
                'validators' => array(
                    array(
                        'validator' => 'StringLength',
                        'options'   => array(
                            0 ,
                            255,
                            'messages' => array(
                                Zend_Validate_StringLength::TOO_LONG =>'Zu lang.',
                                Zend_Validate_StringLength::TOO_SHORT =>'Mindestens 8 Zeichen.'
                            )
                        )
                    )
                )
            )
        ));
    }
    /**
     * Form Element Phone
     *
     * @param boolean $required
     * @param string  $label
     *
     * @return Zend_Form_Element_Text
     */    public function phone($required = false, $label = 'Telefon')
    {
        return new Zend_Form_Element_Text(
            'phone',
            array(
                'label' => $label,
                'validators' => array(
                    //$this->_validateNotEmpty($required, $label),
                    array(
                       'validator'   => 'Regex',
                       'breakChainOnFailure' => true,
                       'options'     => array(
                           'pattern' => '/^[+]?[-\d() .]*$/i',
                           'messages' => array(
                               Zend_Validate_Regex::NOT_MATCH =>'Bitte geben Sie eine gültige Telefonnummer ein.'

                           )
                       )
                    )
                )
            )
        );
    }
    /**
     * Form Element Firstname
     *
     * @param boolean $required
     * @param string  $label
     *
     * @return Zend_Form_Element_Textarea
     */
    public function message($required = false, $label = 'Mitteilung', $length = 255)
    {
        return new Zend_Form_Element_Textarea(
            'message',
            array(
                'label' => 'Mitteilung',
                'validators' => array(
                    array(
                        'validator' => 'StringLength',
                        'options'   => array(
                            0 ,
                            255,
                            'messages' => array(
                                Zend_Validate_StringLength::TOO_LONG =>'Ihre Mitteilung ist zu lang.'
                            )
                        )
                    )
                )
            )
        );
    }
    /**
     * Form Element E-Mail
     *
     * @param boolean $required
     * @param string  $label
     *
     * @return Zend_Form_Element_Text
     */
    public function email($required = false, $label = 'E-Mail')
    {

        $this->addElement(
            new Zend_Form_Element_Text(
                'email',
                array(
                    'label' => $label,
                    'validators'    => array(
                        $this->_validateNotEmpty(true, $label),
                        array(
                            'validator' => 'StringLength',
                            'options' => array(
                                6, 8, 'messages' => array(
                                    'stringLengthTooShort'  => $this->_language['stringLengthTooShort'],
                                    'stringLengthTooLong'   => $this->_language['stringLengthTooLong']
                        )))

                    )
                )
            )
        );
        $this->email->setRequired($required);
    }

    /**
     * Form Element Submit
     *
     * @return Zend_Form_Element_Submit
     */
    public function send()
    {
        $this->addElement(
            new Zend_Form_Element_Submit(
                'send',
                array(
                    'label' => 'verschicken'
                )
            )
        );
    }
    /**
     * Form Object
     *
     * @return Zend_Form
     */
    public function renderForm()
    {
        return $this;
    }

}